load("//:build/eslint_test.bzl", "eslint_test")
load("//:build/wd_ts_project.bzl", "wd_ts_project")
load("//:build/wpt_test.bzl", "wpt_test")

srcs = glob(
    [
        "**/*.ts",
    ],
)

filegroup(
    name = "harness@js",
    srcs = [file.removesuffix(".ts") + ".js" for file in glob(["harness/*.ts"])],
)

wd_ts_project(
    name = "wpt-all@tsproject",
    srcs = srcs,
    source_map = False,
    tsconfig_json = "tsconfig.json",
    deps = [
        "//:node_modules/@types/node",
    ],
)

eslint_test(
    name = "wpt-all",
    srcs = srcs,
    data = [
        "//:node_modules/@types/node",
    ],
    eslintrc_json = "eslint.config.mjs",
    tsconfig_json = "tsconfig.json",
)

wpt_test(
    name = "url",
    config = "url-test.ts",
    wpt_directory = "@wpt//:url@module",
)

wpt_test(
    name = "urlpattern",
    # We use a fixed compat date because new URLPattern implementation
    # will be the default one on a later date.
    compat_date = "2025-04-09",
    config = "urlpattern-test.ts",
    wpt_directory = "@wpt//:urlpattern@module",
)

wpt_test(
    name = "urlpattern-standard",
    config = "urlpattern-standard-test.ts",
    wpt_directory = "@wpt//:urlpattern@module",
)

wpt_test(
    name = "dom/abort",
    config = "dom/abort-test.ts",
    wpt_directory = "@wpt//:dom/abort@module",
)

wpt_test(
    name = "dom/events",
    compat_flags = ["pedantic_wpt"],
    config = "dom/events-test.ts",
    wpt_directory = "@wpt//:dom/events@module",
)

wpt_test(
    name = "fetch/api",
    size = "large",
    config = "fetch/api-test.ts",
    start_server = True,
    target_compatible_with = select({
        # TODO(later): Provide a Windows version of the sidecar script we wrote to invoke wptserve.
        # Currently we only have a Unix shell script.
        "@platforms//os:windows": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
    wpt_directory = "@wpt//:fetch/api@module",
)

wpt_test(
    name = "encoding",
    config = "encoding-test.ts",
    wpt_directory = "@wpt//:encoding@module",
)

wpt_test(
    name = "compression",
    config = "compression-test.ts",
    wpt_directory = "@wpt//:compression@module",
)

wpt_test(
    name = "WebCryptoAPI",
    size = "enormous",
    compat_flags = ["disable_fast_jsg_struct"],
    config = "WebCryptoAPI-test.ts",
    target_compatible_with = select({
        # Too slow on Windows
        "@platforms//os:windows": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
    wpt_directory = "@wpt//:WebCryptoAPI@module",
)

wpt_test(
    name = "streams",
    size = "large",
    config = "streams-test.ts",
    wpt_directory = "@wpt//:streams@module",
)

wpt_test(
    name = "fs",
    size = "large",
    compat_flags = ["enable_web_file_system"],
    config = "fs-test.ts",
    wpt_directory = "@wpt//:fs@module",
)

wpt_test(
    name = "performance-timeline",
    config = "performance-timeline-test.ts",
    wpt_directory = "@wpt//:performance-timeline@module",
)
